package controller.login;


import controller.register.CheckRegister;
import javax.faces.application.FacesMessage;
import javax.faces.component.UIComponent;
import javax.faces.component.UIInput;
import javax.faces.context.FacesContext;
import javax.faces.validator.FacesValidator;
import javax.faces.validator.Validator;
import javax.faces.validator.ValidatorException;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
/**
 *
 * @author HTTHANH
 */
@FacesValidator("passwordValidator")
public class PasswordValidator implements Validator {

    @Override
    public void validate(FacesContext context, UIComponent component, Object value) throws ValidatorException {
        String password = value.toString();

  
        if(CheckTaiKhoan.user!=null){
        String username=CheckTaiKhoan.user;
        // Let required="true" do its job.
        if (password == null || password.isEmpty() || username == null
                || username.isEmpty()) {
            return;
        }
      
        if (!CheckTaiKhoan.getcheck(username, password)) {
           
            throw new ValidatorException(new FacesMessage(
                    "Dang nhap khong hop le."));
        }
        }

    }
}
